﻿using SuporeSliplampApp.Util;
using SuporeSliplampApp.ViewModels;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static SuporeSliplampApp.Views.IDSettingView;

namespace SuporeSliplampApp.Views
{
    /// <summary>
    /// HomeView.xaml 的交互逻辑
    /// </summary>
    public partial class HomeView : Window
    {
        private List<Expander> expanders = new List<Expander>();
        public HomeView()
        {
            this.DataContext = HomeViewModel.homeViewModel;
            InitializeComponent();
            expanders.Add(expander1);
            expanders.Add(expander2);
            expanders.Add(expander3);

            Loaded += HomeView_Loaded;
        }

        private void HomeView_Loaded(object sender, RoutedEventArgs e)
        {
            Common.picpostion = picpos.PointToScreen(new System.Windows.Point(0, 0));
        }

        private void expander1_Expanded(object sender, RoutedEventArgs e)
        {
            Expander expander = sender as Expander;
            if (expander == null) return;
            foreach (var item in expanders)
            {
                if (item.Name != expander.Name)
                {
                    item.IsExpanded = false;
                }
            }
        }

        private void home_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void minBtn_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void closeBtn_Click(object sender, RoutedEventArgs e)
        {
            string content;
            if (Common.languageCode == "zh-CN")
            {
                content = "确定退出程序吗？";
            }
            else
            {
                content = "Do you want to exit the software ?";
            }
            MessageBoxResult result = MessageView.Show(content, "确认", MessageBoxButton.OKCancel);
            //MessageBoxResult res = MessageBox.Show("确定退出程序吗?", "退出", MessageBoxButton.YesNo, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.DefaultDesktopOnly);
            if (result == MessageBoxResult.OK)
            {
                this.Close();
            }

        }

        private void NewPatientBtn_Click(object sender, RoutedEventArgs e)
        {
            NewPatientView newPatientWindow = new NewPatientView();
            newPatientWindow.Owner = this;
            newPatientWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            newPatientWindow.ShowDialog();
        }

        private void OpenPatientBtn_Click(object sender, RoutedEventArgs e)
        {
            OpenPatients openPatients = new OpenPatients();
            openPatients.Owner = this;
            openPatients.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            openPatients.ShowDialog();
        }

        private void ImportPatientBtn_Click(object sender, RoutedEventArgs e)
        {
            ImpDCM impDCM = new ImpDCM();
            impDCM.Owner = this;
            impDCM.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            impDCM.ShowDialog();
        }

        private void BarCodeBtn_Click(object sender, RoutedEventArgs e)
        {

        }

        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            foreach (Window window in Application.Current.Windows)
            {
                if (window is PicEditView)
                {
                    window.Close();
                    break;
                }
            }
        }

        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            EditPortWindow editPortWindow = new EditPortWindow();
            editPortWindow.Owner = this;
            editPortWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            editPortWindow.ShowDialog();
        }



        private void RadioButton_Checked_1(object sender, RoutedEventArgs e)
        {

        }

        private void OpenPatientBtn_Checked(object sender, RoutedEventArgs e)
        {

        }

        private void IDSetting_Click(object sender, RoutedEventArgs e)
        {
            IDSettingView iDSetting = new IDSettingView();
            iDSetting.Owner = this;
            iDSetting.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            iDSetting.ShowDialog();
        }


        private void ProfileButton_Click(object sender, RoutedEventArgs e)
        {
            profilePopup.IsOpen = !profilePopup.IsOpen;
        }

        private void quit_Click(object sender, RoutedEventArgs e)
        {
            //this.Close();
            string exePath = Process.GetCurrentProcess().MainModule.FileName;

            Application.Current.Shutdown();

            Process.Start(exePath);

        }

        private void Usersetting_Click(object sender, RoutedEventArgs e)
        {
            UserSettingView userSettingView = new UserSettingView();
            userSettingView.Owner = this;
            userSettingView.WindowStartupLocation = WindowStartupLocation.CenterScreen ;
            userSettingView.ShowDialog();

        }


        private void CSVBtn_Click(object sender, RoutedEventArgs e)
        {
            CSVView csvView = new CSVView();
            csvView.Owner = this;
            csvView.WindowStartupLocation= WindowStartupLocation.CenterScreen;
            csvView.ShowDialog();
        }

        private void LanguageSet_Click(object sender, RoutedEventArgs e)
        {
            LanguageSetView languageSetView = new LanguageSetView();
            languageSetView.Owner = this;
            languageSetView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            languageSetView.ShowDialog();
        }

        private void DateSet_Click(object sender, RoutedEventArgs e)
        {
            DateSettingView dateSettingView = new DateSettingView();
            dateSettingView.Owner = this;
            dateSettingView.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            dateSettingView.ShowDialog();
        }

        private void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            PrintSetting printSetting = new PrintSetting();
            printSetting.Owner = this;
            printSetting.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            printSetting.ShowDialog();

        }
    }
}
